package com.yijinsuo.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.yijinsuo.R;
import com.yijinsuo.base.BaseActivity;
import com.yijinsuo.http.HttpCallBack;
import com.yijinsuo.http.HttpUtils;
import com.yijinsuo.mian.Config;
import com.yijinsuo.view.TitleBar;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 新手指引
 */
public class NewGuideActivity extends BaseActivity {

    @Bind(R.id.titlebar)
    TitleBar titlebar;
    //
    @Bind(R.id.pb_loading)
    ProgressBar pbLoading;
    @Bind(R.id.mWebView)
    WebView vWVContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_new_guide);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {

        titlebar.setTitleBar(R.drawable.back_selector,"新手指引",0);
    }

    @Override
    protected void initView() {


        //初始化WebView
        vWVContent.setWebViewClient(new WebViewClient());
        vWVContent.getSettings().setJavaScriptEnabled(true);
        vWVContent.getSettings().setBuiltInZoomControls(true); //显示放大缩小 controler
        vWVContent.getSettings().setSupportZoom(true); //可以缩放
        //屏幕自适应
        vWVContent.getSettings().setUseWideViewPort(true);
        vWVContent.getSettings().setLoadWithOverviewMode(true);
        vWVContent.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                pbLoading.setProgress(newProgress);
                if (newProgress == 100) {
                    pbLoading.setVisibility(View.GONE);
                }

            }

        });
    }

    @Override
    protected void setData() {

        HttpUtils.get(Config.FEESUMMARY, new HttpCallBack(this,"加载中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
               if (null!=result){
                   String url=result.optString("url");
                   vWVContent.loadUrl(url);
               }
            }

            @Override
            public void onError(String code, String message) {

                Toast.makeText(NewGuideActivity.this, message, Toast.LENGTH_SHORT).show();

            }
        });


    }

    @OnClick({R.id.titlebar_iv_back})
    @Override
    public void widgetClick(View v) {

        switch (v.getId()){

            case R.id.titlebar_iv_back:

                finish();

                break;

            default:
        }
    }
}
